<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        #nav{
            height: 50px;
            line-height: 50px;
            background-color: pink;
        }
        #nav a{
            text-decoration: none;
            font-size: 30px;
            margin-left: 15px;
        }
        #box{
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            width: 300px;
            height: 300px;
            border: 1px solid #000;
        }
        #box h2{
            border-bottom: 1px solid #000;
            height: 50px;
            line-height: 50px;
            font-size: 20px;
            background-color: orange;
            /* 鼠标便拖拽 */
            cursor: move;
        }
        #box span{
            float: right;
            margin-right: 10px;
            font-size: 20px;
        }
    </style>
</head>
<body>
    <div id="nav">
        <a href="#">注册信息</a>
    </div>
    <div id="box">
        <h2>
            注册信息（可以拖拽）
            <span>关闭</span>
        </h2>
    </div>
</body>
</html>
<script>
    var box = document.querySelector('#box')
    var bat = document.querySelector('h2')
    
    bat.onmousedown = function(event){
        event = event || window.event
        var x = event.clientX
        var y = event.clientY
        var a = box.offsetLeft
        var b = box.offsetTop

        document.onmousemove = function(event){
            event = event || window.event
            var moveX = event.clientX - x + a
            var moveY = event.clientY - y + b
            console.log(moveX)
            console.log(moveY)
            box.style.left = moveX + 'px'
            box.style.top = moveY + 'px'

            window.getSelection()?window.getSelection().removeAllRanges():document.selection.empty();
        }
        document.onmouseup = function(){
            document.onmousemove =''
        }
    }
    
</script>